package killer.board.qna.service;

import java.util.HashMap;
import java.util.List;

import killer.board.common.BoardVO;
import killer.board.qna.model.QnaBoardDao;
import killer.board.qna.model.QnaBoardVO;
import killer.exception.DBUpdateFailException;
import killer.paging.CommonConstants;
import killer.paging.ListVO;
import killer.paging.PagingBean;

public class QnaBoardServiceImpl extends QnaBoardService{
	private QnaBoardDao qnaBoardDao;
	public QnaBoardServiceImpl(QnaBoardDao qnaBoardDao){
		this.qnaBoardDao=qnaBoardDao;
	}

	@Override
	public BoardVO registerBoardWriting(BoardVO bvo) throws Exception {
		// TODO Auto-generated method stub
		QnaBoardVO paramQbvo=(QnaBoardVO)bvo;
		this.qnaBoardDao.insertQna(paramQbvo);
		String qnaDate=this.qnaBoardDao.selectQnaBoardDate(paramQbvo.getQnaNo());
		paramQbvo.setQnaDate(qnaDate);
		return paramQbvo;
	}

	@Override
	public ListVO getBoardWritingList(int nowPage)  throws Exception{
		// TODO Auto-generated method stub
		HashMap paramMap=new HashMap<>();
		paramMap.put("nowPage", nowPage);
		paramMap.put("contentNumPerPageOfQna", CommonConstants.CONTENT_NUM_PER_PAGE_OF_QNA);
		List<QnaBoardVO> list=this.qnaBoardDao.selectQnaList(paramMap);
		
		int totalContent=this.qnaBoardDao.selectQnaBoardNum();
		PagingBean pagingBean=new PagingBean(totalContent, nowPage);
		
		ListVO listVO=new ListVO(list, pagingBean);
		return listVO;
	}

	@Override
	public BoardVO getBoardWritingByNo(int boardNo)  throws Exception{
		// TODO Auto-generated method stub
		return this.qnaBoardDao.selectQnaByNo(boardNo);
	}

	@Override
	public BoardVO registerReply(BoardVO bvo)  throws Exception{
		// TODO Auto-generated method stub
		QnaBoardVO paramQbvo=(QnaBoardVO)bvo;
		this.qnaBoardDao.updateQnaReplyStepByRefAndNowStep(paramQbvo);
		paramQbvo.setRestep(paramQbvo.getRestep()+1);
		paramQbvo.setRelevel(paramQbvo.getRelevel()+1);
		this.qnaBoardDao.insertQnaReply(paramQbvo);
		String qnaDate=this.qnaBoardDao.selectQnaBoardDate(paramQbvo.getQnaNo());
		paramQbvo.setQnaDate(qnaDate);
		return paramQbvo;
	}

}












